#include "Plane.h"

Plane::Plane()
{
	m_normal = Vector3::ZERO;
	m_constant = 0.0;
}

Plane::Plane( const Vector3& normal, Real constant )
{
	m_normal = normal;
	m_constant = constant;
}

Plane::Plane( const Vector3& normal, const Vector& point )
{
	m_normal = normal;
	m_constant = normal.dot( point );
}

Plane::Plane( const Vector3& point0, const Vector3& point1, const Vector3& point2 )
{
	Vector3 edge1 = point1 - point0;
	Vector3 edge2 = point2 - point0;
	m_normal = edge1.unit_cross( edge2 );
	m_constant = m_normal.dot( point0 );
}

Real Plane::distance_to( const Vector3& point ) const
{
	return m_normal.dot( point ) - m_constant;
}

Plane::Side Plane::which_side( const Vector3& point ) const
{
	Real distance = distance_to( point );

	if ( distance < 0.0 )
		return Plane::NEGATIVE_SIDE;

	if ( distance > 0.0 )
		return Plane::POSITIVE_SIDE;

	return Plane::NO_SIDE;
}

